package com.fr.plugin.oauth2;

import com.fr.config.*;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.record.analyzer.EnableMetrics;

@Visualization(category = "Plugin-Config_Group")
@EnableMetrics
public class PluginSimpleConfig extends DefaultConfiguration {

    private static volatile PluginSimpleConfig config = null;

    @Focus(id="com.fr.plugin.oauth2", text = "Plugin-Config_Group", source = Original.PLUGIN)
    public static PluginSimpleConfig getInstance() {
        if (config == null) {
            config = ConfigContext.getConfigInstance(PluginSimpleConfig.class);
        }
        return config;
    }
    @Identifier(value = "authorizeUrl", name = "Plugin-Config_Property_AuthorizeUrl", description = "", status = Status.SHOW)
    private Conf<String> authorizeUrl = Holders.simple("https://gitee.com/oauth/authorize");

    @Identifier(value = "tokenUrl", name = "Plugin-Config_Property_TokenUrl", description = "", status = Status.SHOW)
    private Conf<String> tokenUrl = Holders.simple("https://gitee.com/oauth/token");

    @Identifier(value = "userInfoUrl", name = "Plugin-Config_Property_UserInfoUrl", description = "", status = Status.SHOW)
    private Conf<String> userInfoUrl = Holders.simple("https://gitee.com/api/v5/user");

    @Identifier(value = "clientId", name = "Plugin-Config_Property_ClientId", description = "", status = Status.SHOW)
    private Conf<String> clientId = Holders.simple("17d1a88aa442d8af75c36bb2a4607c5540831db0408346c59836009e0d980a48");
    @Identifier(value = "clientSecret", name = "Plugin-Config_Property_ClientSecret", description = "", status = Status.SHOW)
    private Conf<String> clientSecret = Holders.simple("989d06c397c84fe3bd7bac8d50112845d3a3b0f5d9833a7d9c22ab1185c49d01");

    @Identifier(value = "logoutUrl", name = "Plugin-Config_Property_LogoutUrl", description = "", status = Status.SHOW)
    private Conf<String> logoutUrl = Holders.simple("https://gitee.com/oauth/logout");

    @Identifier(value = "userName", name = "Plugin-Config_Property_UserName", description = "", status = Status.SHOW)
    private Conf<String> userName = Holders.simple("loginName");
    @Identifier(value = "baseUrl", name = "Plugin-Config_Property_BaseUrl", description = "", status = Status.SHOW)
    private Conf<String> baseUrl = Holders.simple("http://localhost:8080/webroot");

    @Identifier(value = "loginUrl", name = "Plugin-Config_Property_LoginUrl", description = "", status = Status.SHOW)
    private Conf<String> loginUrl = Holders.simple("/decision/login");
    @Identifier(value = "forceReLogin", name = "Plugin-Config_Property_ForceReLogin", description = "", status = Status.SHOW)
    private Conf<String> forceReLogin = Holders.simple("relogin");
    @Identifier(value = "enabled", name = "Plugin-Config_Property_Enabled", description = "", status = Status.SHOW)
    private Conf<Boolean> enabled = Holders.simple(true);

    public String getBaseUrl() {
        return baseUrl.get();
    }

    public void setBaseUrl(String baseUrl) {
        this.baseUrl.set(baseUrl);
    }

    public String getTokenUrl() {
        return tokenUrl.get();
    }

    public void setTokenUrl(String tokenUrl) {
        this.tokenUrl.set(tokenUrl);
    }

    public String getUserInfoUrl() {
        return userInfoUrl.get();
    }

    public void setUserInfoUrl(String userInfoUrl) {
        this.userInfoUrl.set(userInfoUrl);
    }

    public String getClientId() {
        return clientId.get();
    }

    public void setClientId(String clientId) {
        this.clientId.set(clientId);
    }

    public String getClientSecret() {
        return clientSecret.get();
    }

    public void setClientSecret(String clientSecret) {
        this.clientSecret.set(clientSecret);
    }

    public String getAuthorizeUrl() {
        return authorizeUrl.get();
    }

    public void setAuthorizeUrl(String authorizeUrl) {
        this.authorizeUrl.set(authorizeUrl);
    }

    public String getLogoutUrl() {
        return logoutUrl.get();
    }

    public void setLogoutUrl(String logoutUrl) {
        this.logoutUrl.set(logoutUrl);
    }

    public String getUserName() {
        return userName.get();
    }

    public void setUserName(String userName) {
        this.userName.set(userName);
    }

    public String getLoginUrl() {
        return loginUrl.get();
    }

    public void setLoginUrl(String loginUrl) {
        this.loginUrl.set(loginUrl);
    }

    public String getForceReLogin() {
        return forceReLogin.get();
    }

    public void setForceReLogin(String forceReLogin) {
        this.forceReLogin.set(forceReLogin);
    }

    public boolean isEnabled() {
        return enabled.get();
    }

    public void setEnabled(boolean enabled) {
        this.enabled.set(enabled);
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        PluginSimpleConfig cloned = (PluginSimpleConfig) super.clone();
        cloned.authorizeUrl = (Conf<String>) this.authorizeUrl.clone();
        cloned.clientId = (Conf<String>) this.clientId.clone();
        cloned.clientSecret = (Conf<String>) this.clientSecret.clone();
        cloned.loginUrl = (Conf<String>) this.loginUrl.clone();
        cloned.forceReLogin = (Conf<String>) this.forceReLogin.clone();
        cloned.logoutUrl = (Conf<String>) this.logoutUrl.clone();
        cloned.tokenUrl = (Conf<String>) this.tokenUrl.clone();
        cloned.userInfoUrl = (Conf<String>) this.userInfoUrl.clone();
        cloned.userName = (Conf<String>) this.userName.clone();
        cloned.enabled = (Conf<Boolean>) this.enabled.clone();
        return cloned;
    }

}
